//
//  LMMeCollectionCell.m
//  舍品
//
//  Created by 楼 眉 on 16/3/21.
//  Copyright © 2016年 楼 眉. All rights reserved.
//
static            CGFloat              const                KTitleFontValue              =               12.0;
static            CGFloat              const                KClassifyLableFontValue              =               11.0;

#define KitemHeight (SCREEN_WIDTH - 20 *kUnit - 20*kUnit) / 1.8

#import "LMMeCollectionCell.h"
#import "LMPost.h"
#import <YYWebImage.h>
@interface LMMeCollectionCell ()
@property (nonatomic,weak)  UIImageView *pictureImageView;
@property (nonatomic,weak)  UILabel *timeLabel;
@property (nonatomic,weak)  UILabel *titleLabel;
@property (nonatomic,weak)  UIView *geduanView;
@property (nonatomic,weak)  UIImageView *classifyImageView;
@property (nonatomic,weak)  UILabel *classifyLabel;
@end
@implementation LMMeCollectionCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        UIImageView *pictureImageView = [[UIImageView alloc]init];
        self.pictureImageView = pictureImageView;
        [self.contentView addSubview:pictureImageView];
        
        UIImageView *classifyImageView = [[UIImageView alloc]init];
        self.classifyImageView = classifyImageView;
        classifyImageView.backgroundColor = [UIColor blackColor];
        classifyImageView.alpha = 0.3;
        [pictureImageView addSubview:classifyImageView];
        
        UILabel *classifyLabel = [[UILabel alloc]init];
        classifyLabel.numberOfLines = 0;
        classifyLabel.textColor = [UIColor whiteColor];
        classifyLabel.textAlignment = NSTextAlignmentCenter;
        classifyLabel.font = [UIFont systemFontOfSize:KClassifyLableFontValue];
        self.classifyLabel = classifyLabel;
        [self.pictureImageView addSubview:classifyLabel];
        
        UILabel *timeLabel = [[UILabel alloc]init];
        self.timeLabel = timeLabel;
        [self.contentView addSubview:timeLabel];
        
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.font = [UIFont systemFontOfSize:KTitleFontValue];
        titleLabel.numberOfLines = 0;
        titleLabel.textColor = [UIColor lightGrayColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel = titleLabel;
        [self.contentView addSubview:titleLabel];
        
        UIView *geduanView = [[UIView alloc]init];
        self.geduanView = geduanView;
        geduanView.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:geduanView];
        
}
    return self;
}

- (void)setPost:(LMPost *)post
{
    _post = post;
    self.pictureImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.pictureImageView.clipsToBounds = YES;
    
    NSMutableArray *images = [NSMutableArray array];
    NSArray *contents = post[@"contentArray"];
    NSString *classify = post[@"classify"];
    if ([classify isEqualToString:@"s"]) {
        self.classifyLabel.text = @"已分类到秀一秀";
    }else if ([classify isEqualToString:@"e"])
    {
        self.classifyLabel.text = @"已分类到评一评";
    }else
    {
        self.classifyLabel.text = @"还在审核中";
    }
    for (NSDictionary *dict in contents) {
        for (NSString *key in dict.allKeys) {
            if ([key isEqualToString:@"image"]) {
                [images addObject:dict];
            }
        }
    }
    NSDictionary *firsDIct = [images firstObject];
    if (firsDIct) {
        [self.pictureImageView yy_setImageWithURL:[NSURL URLWithString:firsDIct[@"image"]] placeholder:nil];
    }else
    {
        self.pictureImageView.image = [UIImage imageNamed:@"touxiang.png"];
    }
    
    self.titleLabel.text = post.title;
}

- (void)layoutSubviews
{
    self.pictureImageView.frame = CGRectMake(0, 0, (SCREEN_WIDTH - 20 *kUnit - 20*kUnit) / 2, KitemHeight/ 3 *2);
    self.classifyImageView.frame = CGRectMake(0, 0, self.pictureImageView.width , self.pictureImageView.height / 5);
    self.classifyLabel.frame = CGRectMake(0, 1*kUnit, self.pictureImageView.width, self.pictureImageView.height / 5 - 2*kUnit);
    self.titleLabel.frame = CGRectMake(0, CGRectGetMaxY(self.pictureImageView.frame), self.pictureImageView.width, KitemHeight / 3 *0.6);
    self.geduanView.frame = CGRectMake(20*kUnit, CGRectGetMaxY(self.titleLabel.frame), self.pictureImageView.width - 40*kUnit, 1*kUnit);
}
@end
